#!/bin/bash
# 定义一个数组来存储节点ID
declare -a node_ids=(node101 node102 node103)
opt=$1
shift
new_node_ids=("$@")
# 遍历传入的节点ID
for node_id in "${new_node_ids[@]}"; do
    # 检查节点ID是否已经在数组中
    if [[ ! "${node_ids[*]}" =~ ${node_id} ]]; then
        # 如果不在数组中，则添加
        node_ids+=("$node_id")
    fi
done

case $opt in
"start"){
	for i in "${node_ids[@]}"
	do
        echo ---------- zookeeper $i 启动 ------------
		ssh $i "$ZOOKEEPER_HOME/bin/zkServer.sh start"
	done
};;
"stop"){
	for i in "${node_ids[@]}"
	do
        echo ---------- zookeeper $i 停止 ------------    
		ssh $i "$ZOOKEEPER_HOME/bin/zkServer.sh stop"
	done
};;
"status"){
	for i in "${node_ids[@]}"
	do
        echo ---------- zookeeper $i 状态 ------------    
		ssh $i "$ZOOKEEPER_HOME/bin/zkServer.sh status"
	done
};;
esac

